-- 日志工具类
local Logger = {
    DEBUG = 1,
    INFO = 2,
    WARN = 3,
    ERROR = 4
}

-- 日志级别名称映射
local levelNames = {
    [Logger.DEBUG] = "DEBUG",
    [Logger.INFO] = "INFO",
    [Logger.WARN] = "WARN",
    [Logger.ERROR] = "ERROR"
}

-- 当前日志级别
local currentLevel = Logger.INFO

-- 设置日志级别
function Logger.setLevel(level)
    currentLevel = level
end

-- 获取当前日志级别
function Logger.getLevel()
    return currentLevel
end

-- 记录日志
local function log(level, message, data)
    if level < currentLevel then
        return
    end
    
    local timestamp = os.date("%Y-%m-%d %H:%M:%S")
    local levelName = levelNames[level] or "UNKNOWN"
    local logMessage = string.format("[%s][%s] %s", timestamp, levelName, message)
    
    if data then
        if type(data) == "table" then
            logMessage = logMessage .. " " .. table.concat(data, " ")
        else
            logMessage = logMessage .. " " .. tostring(data)
        end
    end
    
    nLog(logMessage)
end

-- 各级别日志函数
function Logger.debug(message, data)
    log(Logger.DEBUG, message, data)
end

function Logger.info(message, data)
    log(Logger.INFO, message, data)
end

function Logger.warn(message, data)
    log(Logger.WARN, message, data)
end

function Logger.error(message, data)
    log(Logger.ERROR, message, data)
end

return Logger 